package com.cls.business.mapper;

import com.cls.business.entity.TopicPlan;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * 课题计划表 Mapper
 *
 * @author wmm
 * @date 2020-11-11 10:45:55
 */
@Repository
public interface TopicPlanMapper extends BaseMapper<TopicPlan> {

    /**
     * 根据年份获取计划
     * @param year
     * @return
     */
    @Select("SELECT  * FROM biz_topic_plan " +
            "WHERE year=#{year} AND is_delete=0 and topic_classify_code=#{topicClassify}")
    TopicPlan selectByYearAndTopicClassify(@Param("year") String year,@Param("topicClassify")String topicClassify);

    /**
     * 根据SelectNoticeId查询
     * @param selectNoticeId
     * @return
     */
    @Select("SELECT  * FROM biz_topic_plan " +
            "WHERE select_notice_id=#{selectNoticeId} AND is_delete=0")
    TopicPlan selectBySelectNoticeId(@Param("selectNoticeId")Long selectNoticeId);

    /**
     * 根据concludeNoticeId查询
     * @param concludeNoticeId
     * @return
     */
    @Select("SELECT  * FROM biz_topic_plan " +
            "WHERE conclude_notice_id=#{concludeNoticeId} AND is_delete=0")
    TopicPlan selectByConcludeNoticeId(@Param("concludeNoticeId")Long concludeNoticeId);



    /**
     * 根据期次查询
     * @param period
     * @return
     */
    @Select("SELECT  * FROM biz_topic_plan " +
            "WHERE period like #{period} AND is_delete=0")
    TopicPlan selectByPeriod(@Param("period")String period );

    /**
     * 根据applyNoticeId查询
     * @param applyNoticeId
     * @return
     */
    @Select("SELECT * FROM biz_topic_plan " +
            "WHERE apply_notice_id=#{applyNoticeId} AND is_delete=0")
    TopicPlan selectByApplyNoticeId(@Param("applyNoticeId")Long applyNoticeId);

    /**
     * 魏起成根据年份更新计划状态
     * @param year
     */
    @Update("UPDATE biz_topic_plan SET status_code=#{statusCode} WHERE year=#{year} AND is_delete=0 ")
    void updateStatusCodeByYear(@Param("year") Integer year,@Param("statusCode") String statusCode);


    @Select("select plan.* from biz_topic topic " +
            "left join biz_topic_plan plan on plan.plan_id = topic.plan_id " +
            "where topic.topic_id = #{topicId} and topic.is_delete=0 and topic.plan_id  is not null ")
    TopicPlan selectByTopicId(@Param("topicId")Long topicId);

    /**
     * 根据preItemNoticeId查询
     * @param preItemNoticeId
     * @return
     */
    @Select("SELECT * FROM biz_topic_plan " +
            "WHERE pre_item_notice_id=#{preItemNoticeId} AND is_delete=0")
    TopicPlan selectByPreItemNoticeId(@Param("preItemNoticeId") Long preItemNoticeId);

    /**
     * 根据结项结果公告id
     * @param concludeFinishNoticeId
     * @return
     */
    @Select("SELECT * FROM biz_topic_plan " +
            "WHERE conclude_finish_notice_id=#{concludeFinishNoticeId} AND is_delete=0")
    TopicPlan selectByConcludeFinishNoticeId(Long concludeFinishNoticeId);

    /**
     * 根据结项立项公告id
     * @param itemNoticeId
     * @return
     */
    @Select("SELECT * FROM biz_topic_plan " +
            "WHERE item_notice_id=#{itemNoticeId} AND is_delete=0")
    TopicPlan selectItemNoticeId(Long itemNoticeId);
    /**
     * 根据结项立项公告id
     * @param concludeFinishNoticeId
     * @return
     */
    @Select("SELECT * FROM biz_topic_plan " +
            "WHERE conclude_finish_notice_id=#{concludeFinishNoticeId} AND is_delete=0")
    TopicPlan selectNoticeByConcludeFinishNoticeId(Long concludeFinishNoticeId);
}
